import React from 'react';
import { Menu, Icon } from 'antd';
import './index.css';

export default class SiderMenu extends React.Component {
	state = {
		choseItem:[],
	}
 componentDidMount(){
	 if(this.state.choseItem && this.state.choseItem.length > 0) {
		this.props.history.push(`/${this.state.choseItem}`)
	 }
	 if(sessionStorage.getItem('fAddress')){
        this.setState({
			choseItem:sessionStorage.getItem('fAddress').split(",")
		})
	 }
 }
	// 切换菜单 
	handleClick = (e) => {
		this.props.history.push(`/${e.key}`)
		this.setState({
			choseItem: [e.key]
		});
        sessionStorage.setItem('fAddress',[e.key])
	};

	render() {
		return (
			<div style={{height: 'inherit'}}>
				<div className='topIcon' >
					<img src={require('../../assets/logo.png')} style={{width:'40px',height:'40px'}}/>
				</div>
				<Menu
					onClick={this.handleClick}
					mode="inline"
					selectedKeys={this.state.choseItem}
					style={{fontSize:16}}
				>
					{/* 遍历路由生成路由菜单 */}
					{this.props.menuList.map((data,index) => (
						<Menu.Item key={data.fAddress}>
							<Icon type={data.fMenuIcon} />
							<span>{data.fMenuName}</span>
						</Menu.Item>
					))}
				</Menu>
			</div>
		);
	}
}